<template>
  <el-table :loading="loading" :data="pageDatas" style="width: 100%">
    <el-table-column prop="no" label="编号" align="center" />
    <el-table-column prop="type" label="类型" align="center" />
    <el-table-column prop="name" label="名称" align="center" />
    <el-table-column prop="manager" label="管理员" align="center" />
    <el-table-column prop="phone" label="手机" align="center" />
    <el-table-column prop="password" label="密码" align="center" />
    <el-table-column prop="hospitalId" label="医院id" align="center" />
    <el-table-column prop="hospitalName" label="医院名字" align="center" />
    <el-table-column fixed="right" label="操作" align="center">
      <template slot-scope="scope">
        <el-button type="text" size="small">查看</el-button>
        <el-button type="text" size="small">编辑</el-button>
        <el-button type="text" size="small" @click="deleteBtn(scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>
<pagination :page-num="params.page" :page-size="params.pageSize" :on-change="handlePaginationChange" :total="total" />

<script>
export default {
  data() {
    return {
      searchForm: {},
      options: [],
      pageDatas: [],
      params: {
        page: 1,
        pageSize: this.$store.state.commonsettings.maxPageSize,
      },
      total: 0,
      addData: {}, // 添加数据
      selectData: {},
      flag: true,
      title: "",
      testBtn: "",
      visible: false,
      show: true,
      widths: 50,
      loading: false,
    };
  },
  created() {
    this.getPageDatas();
  },
  methods: {
    async getPageDatas() {
      this.loading = true;
      const res = await this.$api['data/promotion/page']({ ...this.params, ...this.searchForm });
      this.loading = false;
      if (res.code !== 200) return this.$message.error('查询顾客列表失败！');
      this.pageDatas = res.data.result;
      this.total = res.data.total;
    },
    handlePaginationChange(val) {
      this.params = { page: val.pageNum, pageSize: val.pageSize };
      this.getPageDatas();
    },
    // 添加
    addDataBtn() {

    },
    // 搜索
    searchBtn() {
      this.getPageDatas();
    },
    // 详情
    async detailsBtn(row) {
      const res = await this.$api['data/promotion/details']({ id: row.id });
      if (res.code !== 200) return this.$message.error('查看详情失败！');
      this.selectCustomersData = res.data;
      this.show = false;
      this.flag = false;
      this.widths = 70;
      this.visible = true;
    },
    // 提交
    async submitForm() {
      this.loading = true;
      const res = await this.$api['data/promotion/add']({ ...this.addData });
      this.loading = false;
      if (res.code !== 200) return this.$message.error('新增失败！');
      this.$message.success('添加成功！');
      this.getPageDatas();
      this.visible = false;
    },
    // 删除
    async deleteBtn(row) {
      const confirmResult = await this.$confirm('请确认是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).catch((err) => err);
      if (confirmResult !== 'confirm') {
        return this.$message.info('已取消删除');
      }
      const res = await this.$api['data/promotion/delete']({ id: row.id });
      if (res.code !== 200) return this.$message.error('删除推广机构失败！');
      this.$message.success('删除推广机构成功！');
      this.getPageDatas();
    },
    // 批量删除
    async batchDeleteBtn(row) {
      const confirmResult = await this.$confirm('请确认是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).catch((err) => err);
      if (confirmResult !== 'confirm') {
        return this.$message.info('已取消删除');
      }
      const res = await this.$api['data/promotion/batchdelete']({ id: row.id });
      if (res.code !== 200) return this.$message.error('删除推广机构失败！');
      this.$message.success('删除推广机构成功！');
      this.getPageDatas();
    },
  },
};
</script>
